import { defineConfig } from 'vite'
import react from '@vitejs/plugin-react-swc'
import { resolve } from 'path'

// https://vitejs.dev/config/
export default defineConfig({
  plugins: [react()],
  resolve: {
    alias: [
      {
        find: '/@',
        replacement: resolve(__dirname, './src')
      }
    ]
  },
  build: {
    rollupOptions: {
      input: {
        main: resolve(__dirname, 'index.html'),
        platform: resolve(__dirname, 'platform/index.html'),
        wms: resolve(__dirname, 'wms/index.html'),
      },
      output:{
        manualChunks(id){
          if (id.includes('node_modules')) {
            return 'vendor'
          }
        },
        entryFileNames:(chunkInfo) =>{
          // console.log('entry',chunkInfo)
          return '[name]/[name].[hash].js'
        },
        chunkFileNames:(chunkInfo) =>{
          // console.log('chunk',chunkInfo)
          if(chunkInfo.name.includes("platform")){
            return '[name]/chunk/[name].[hash].js'
          }
          if(chunkInfo.name.includes("wms")){
            return '[name]/chunk/[name].[hash].js'
          }
          return 'chunk/[name].[hash].js'
        },
        assetFileNames:(chunkInfo)=>{
          // console.log('asset',chunkInfo)
          return '[name]/[name].[hash].[ext]'
        }
      }
    }
  },
  server: {
    host: '0.0.0.0',
    proxy:{
      '/api/es':{
        target:"http://127.0.0.1:8999",
        changeOrigin: true,
        rewrite: (path) => path.replace(/^\/api/, '')
      },
      '/api/type-manage':{
        target:"http://127.0.0.1:8010",
        changeOrigin: true,
        rewrite: (path) => path.replace(/^\/api/, '')
      }
    }
  }
})
